package com.shu.jdk8;

import com.sun.media.jfxmedia.logging.Logger;

import java.nio.charset.Charset;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/9/30 16:09
 */

public class Java8Tester {
    @FunctionalInterface
    interface MathOperation {
        int operation(int a, int b);
    }
    
    @FunctionalInterface
    interface GreetingService {
        void sayMessage(String message);
    }
    
    public static void main(String args[]) {
        //老版本写法
        MathOperation oldAdd = new MathOperation() {
            @Override
            public int operation(int a, int b) {
                return a + b;
            }
        };
        
        // jdk8类型声明
        MathOperation addition = (int a, int b) -> a + b;
        
        // 不用类型声明
        MathOperation subtraction = (a, b) -> a - b;
        
        // 大括号中的返回语句
        MathOperation multiplication = (int a, int b) -> {
            return a * b;
        };
        
        // 没有大括号及返回语句
        MathOperation pision = (int a, int b) -> a / b;
        
        // 不用括号
        GreetingService greetService1 = message -> System.out.println("Hello " + message);
        
        // 用括号
        GreetingService greetService2 = (message) -> System.out.println("Hello " + message);
        
        greetService1.sayMessage("Runoob");
        
        greetService2.sayMessage("Google");
    
        String x = "滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋滋";
        System.out.println(x);
        int length = x.getBytes(Charset.defaultCharset()).length;
        
        if (length > 128) {
            x = x.substring(0,42);
        }
        System.out.println(x);
        System.out.println(x.getBytes(Charset.defaultCharset()).length);
    }
    
    
    
    
}